package com.qf.kdgroup.gdbackend.controller;

import com.github.pagehelper.PageInfo;
import com.qf.kdgroup.gdbackend.dto.ResultBean;
import com.qf.kdgroup.gdbackend.entity.Auth;
import com.qf.kdgroup.gdbackend.entity.User;
import com.qf.kdgroup.gdbackend.service.UserService;
import com.qf.kdgroup.gdbackend.vo.PageVO;
import com.qf.kdgroup.gdbackend.vo.UserVO;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ResponseBody
    public ResultBean login(@RequestBody UserVO userVO){

        return userService.findByUsername(userVO);
    }

    @PostMapping("/getList")
    public PageInfo getList(@RequestBody PageVO pageVO){
        PageInfo pageInfo = userService.selectAllByPage(pageVO);
        return pageInfo;
    }

    @PostMapping("/add")
    @ResponseBody
    public ResultBean add(@RequestBody User user){
        return userService.add(user);
    }

    @PostMapping("/find")
    @ResponseBody
    public User find(@RequestBody User user){
        return userService.findById(user.getUserid());
    }

    @PostMapping("/update")
    @ResponseBody
    public ResultBean update(@RequestBody User user){
        return userService.update(user);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    public ResultBean delete(@RequestBody User user){
        return userService.deleteById(user.getUserid());
    }

}
